import request from "./request";

export const addPost = (form) => {
  return request({
    url: '/api/post/add',
    method: 'POST',
    data: form,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const getAllPosts = () => {
  return request({
    url: '/api/post/all',
    method: 'GET'
  })
}

export const getPostsByUserId = (userId) => {
  return request({
    url: `/api/post/user/${userId}`,
    method: 'GET'
  })
}

export const deletePost = (postId, userId) => {
  return request({
    url: `/api/post/delete/${postId}?userId=${userId}`,
    method: 'DELETE'
  })
}

export const likePost = (postId,userId) => {
  return request({
    url: `/api/post/like/${postId}?userId=${userId}`,
    method: 'POST'
  })
}

export const unlikePost = (postId,userId) => {
  return request({
    url: `/api/post/unlike/${postId}?userId=${userId}`,
    method: 'DELETE'
  })
}

export const toggleLike = (postId,userId) => {
  return request({
    url: `/api/post/toggle/${postId}?userId=${userId}`,
    method: 'POST'
  })
}

export const getPostsLikedByUser = (userId) => {
  return request({
    url: `/api/post/liked/${userId}`,
    method: 'GET'
  })
}